package cn.yunhe.controller;

import cn.yunhe.entity.User;
import cn.yunhe.service.IAdminService;
import cn.yunhe.service.IUserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/after/UpAllUserServlet")
public class UpAllUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("username");
        String tel = request.getParameter("tel");
        String ad = request.getParameter("address");
        User user1 = (User) request.getSession().getAttribute("oneuser");
        User user = new User();
        user.setUserName(name);
        user.setAddress(ad);
        user.setTelphone(tel);
        int id = user1.getUserId();
        user.setUserId(id);
        IAdminService iAdminService = new IAdminService();
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        if (iAdminService.upAllUser(user)) {
            out.print(1);
        }else {
            out.print(0);
        }


    }
}
